package com.andova.toolkit.util;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.widget.ImageView;

import androidx.annotation.ColorRes;
import androidx.annotation.DrawableRes;
import androidx.core.content.ContextCompat;
import androidx.core.graphics.drawable.DrawableCompat;

/**
 * Created by Administrator on 2018-12-11.
 *
 * @author kzaxil
 * @since 0.0.4
 */
public class DrawableUtil {
    /**
     * {@link Drawable}着色
     */
    public void tintDrawable(Context context, ImageView imageView, @DrawableRes int res, @ColorRes int color) {
        Drawable drawable = ContextCompat.getDrawable(context, res);
        if (drawable == null) return;
        Drawable drawableUp = DrawableCompat.wrap(drawable);
        DrawableCompat.setTint(drawableUp, ContextCompat.getColor(context, color));
        imageView.setImageDrawable(drawableUp);
    }
}
